//
//  ST_RecommendForYouCell.swift
//  btvideo
//
//  Created by mac on 2020/9/28.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit

class ST_RecommendForYouCell: ST_PinterestHomeCell {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        
        contentView.addSubview(sign_for_me_btn)
        sign_for_me_btn.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(8)
            make.height.equalTo(22)
        }
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var sign_for_me_btn:ST_RecommendForYouCellSignView = {
        let control = ST_RecommendForYouCellSignView()
        control.alpha = 0
        return control
    }()
    
    override var model:ST_PinterestHomeCellModel{
        didSet{
            
            if model.isProps{
                sign_for_me_btn.bindGift()
                sign_for_me_btn.alpha = 1
                self.rightSignLabel.isHidden = true
            }
            else if model.lovedMe || model.showedMe{
                sign_for_me_btn.bind(gender: model.gender, isLoved: model.lovedMe)
                sign_for_me_btn.alpha = 1
                self.rightSignLabel.isHidden = true
            }else{
                sign_for_me_btn.alpha = 0
                self.rightSignLabel.isHidden = !model.faceIdentified
            }
            
            
        }
    }
}




class ST_RecommendForYouCellSignView: UIControl {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = UIColor.white
        
        self.cornerRadius = 11
        
        self.addSubview(icon_image_view)
        icon_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(16)
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(9)
        }
        
        self.addSubview(titleLabel)
        titleLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(28)
            make.right.equalToSuperview().offset(-9)
            make.centerY.equalToSuperview()
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

    fileprivate lazy var icon_image_view:UIImageView = {
         let control = UIImageView()
          control.contentMode = .scaleAspectFill
          control.clipsToBounds = true
          return control
      }()

    
    fileprivate lazy var titleLabel:UILabel = {
        let control = UILabel.init()
        control.textColor = UIColor.init(hexString: "#333333")
        control.font = UIFont.systemFont(ofSize: 11, weight: UIFont.Weight.medium)
        return control
    }()
    
    func bindGift(){
        
        titleLabel.text = "心动礼物"
        
        icon_image_view.image = ST_ImageUtils.imageName("RecommendForYouCellSign_gift_icon")
    }
    
    func bind(gender:Int,isLoved:Bool)  {
        
        var str = (gender == 1 ? "他" : "她")
        
        if isLoved{
            str += "喜欢我"
            icon_image_view.image = ST_ImageUtils.imageName("RecommendForYouCellSign_love_icon")
        }else{
            str += "看过我"
            icon_image_view.image = ST_ImageUtils.imageName("RecommendForYouCellSign_showed_icon")
        }
        
        titleLabel.text = str
    }
    
}
